/*================================================================
*   Copyright (C) 2019 Guangzhou Firefly Ltd. All rights reserved.
*   
*   文件名称：key.c
*   创 建 者：luhuadong
*   创建日期：2019年08月30日
*   描    述：
*
================================================================*/


#include "key.h"
#include "led_alert.h"

#define USER_BTN_PIN    GET_PIN(C, 13)

#if 0
/* 按下 & 弹起 不同功能 */
static void key_cb(void *args)
{
	if(PIN_LOW == rt_pin_read(USER_BTN_PIN))
	{
		rt_kprintf("key pressed\n");
		//led_on();
		flag_temp = ON;
	}
	else
	{
		rt_kprintf("key released\n");
		//led_off();
		flag_temp = OFF;
	}
}

#else

/* 按下奇数次 & 偶数次 功能不同 */
static void key_cb(void *args)
{
	if(flag_temp == OFF) {
		flag_temp = ON;
	}
	else {
		flag_temp = OFF;
	}
}
#endif

void key_init()
{
	flag_temp = OFF;
	flag_pm25 = OFF;
	flag_forma = OFF;

	rt_pin_mode(USER_BTN_PIN, PIN_MODE_INPUT_PULLUP);

	rt_pin_attach_irq(USER_BTN_PIN, PIN_IRQ_MODE_RISING_FALLING, key_cb, RT_NULL);
	rt_pin_irq_enable(USER_BTN_PIN, PIN_IRQ_ENABLE);
}

